<?php

namespace haibao\user\business\payment\web;

class UserVip extends \haibao\user\business\Base{
    

    /**
     * @var $_instance
     */
    private static $_instance;
    
    /**
     * instance()
     */
    private static function instance(){
        if(!self::$_instance){
            self::$_instance = new \haibao\user\data\payment\web\UserVip();
        }
        return self::$_instance;
    }
    
    /**
     * 根据用户Id判断是否是vip会员
     */
    public static function getUserVipInfo($userId){
        $cache = new \haibao\user\cache\Payment();
        $vipInfo = $cache->getVipInfo($userId);
        if(!$vipInfo){
            $endDate = self::getUserVipEndDate($userId);
            $vipInfo = array(
                'isVip' => self::getVipByUserId($userId) ? true : false,
                'endDate' => $endDate ? $endDate : '',
            );
            $cache->setVipInfo($userId, $vipInfo);
        }
        return $vipInfo;
    }
    
    /**
     * 获取购买记录
     */
    public static function getVipByUserId($userId){
        return self::instance()->getVipByUserId(intval($userId));
    }
    
    /**
     * 获取购买的截止时间
     */
    public static function getUserVipEndDate($userId){
        return self::instance()->getUserVipEndDate(intval($userId));
    }
    
}